package com.lenovo.export

import org.apache.spark.sql.{SaveMode, SparkSession}

object export_LAN {

  def main(args: Array[String]): Unit = {

    val sparkSession = SparkSession.builder.master("yarn").appName("export_LAN").enableHiveSupport().getOrCreate()

    val prop = new java.util.Properties
    prop.setProperty("user","root")
    prop.setProperty("password","123456")
    prop.setProperty("charset","utf8")
    //指定驱动
    prop.setProperty("driver","com.mysql.jdbc.Driver")

    sparkSession.sql("select * from ccdp.lan_appsoftwaresuite").write.mode(SaveMode.Append).jdbc("jdbc:mysql://10.96.91.186:3306/lenovo_upp_test?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8","lan_appsoftwaresuite",prop) // 表可以不存在
    sparkSession.sql("select * from ccdp.lan_compsystem").write.mode(SaveMode.Append).jdbc("jdbc:mysql://10.96.91.186:3306/lenovo_upp_test?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8","lan_compsystem",prop) // 表可以不存在
    sparkSession.sql("select * from ccdp.lan_computer").write.mode(SaveMode.Append).jdbc("jdbc:mysql://10.96.91.186:3306/lenovo_upp_test?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8","lan_computer",prop) // 表可以不存在
    sparkSession.sql("select * from cctest.ad_user").write.mode(SaveMode.Append).jdbc("jdbc:mysql://10.96.91.186:3306/lenovo_upp_test?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8","ad_user",prop) // 表可以不存在

  }
}
